<template>
    <div>
         <el-table :data="albums" style="width: 100%">
            <el-table-column label="专辑名称">
                <template slot-scope="scope">
                    {{scope.row.albumName}}
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                     <el-tooltip class="item" effect="dark" content="修改专辑名称" placement="top-start">
                        <el-button type="info" icon="el-icon-setting" circle></el-button>
                    </el-tooltip>
                    <el-button @click="removeAlbum(scope.row)" type="danger" icon="el-icon-delete" circle></el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>


<script>
import axios from 'axios';
import { onMounted, ref } from '@vue/composition-api';
export default {
    setup(props, context) {
        axios.defaults.baseURL = 'http://localhost:3000';

        onMounted(() => {
            getAlbums();
        });

        // 专辑
        const albums = ref([]);
        // 获取专辑
        const getAlbums = async function () {
            let { data: res } = await axios.get('/get/albumall/name');
            if (res.status != 200)
                return context.parent.$message.error('获取专辑名称失败，请刷新重试');

            albums.value = res.albums;
        }

        // 删除专辑
        const removeAlbum = async function (item) {
            let { data: res } = await axios.delete(`/set/remove/album/${item.albumName}`);
            if (res.status != 200)
                return context.parent.$message.error('删除专辑失败，请刷新后重试');
            context.parent.$message.success('删除专辑成功');
            getAlbums();
        }

        const methods = { removeAlbum }
        return {
            ...methods,
            albums
        }
    }
}
</script>